
#include "spserver.h"
#include "fd.h"
#include "NetworkObject.h"
#include "Session.h"

Session::Session(size_t nSendBufferSize, size_t nRecvBufferSize, size_t nMaxPacketSize)
{
	m_socket = retired_fd;

	m_pNetworkObject = NULL;

	m_pSendBuffer = new SendBuffer();
	m_pSendBuffer->Create(nSendBufferSize, nMaxPacketSize);

	m_pRecvBuffer = new RecvBuffer();
	m_pRecvBuffer->Create(nRecvBufferSize, nMaxPacketSize);

	m_bRemove = false;
}


Session::~Session(void)
{
}

void Session::BindNetworkObject(NetworkObject* pNetwork)
{
	m_pNetworkObject = pNetwork;
	pNetwork->SetSession(this);
}

void Session::UnBindNetworkObject()
{
	if (m_pNetworkObject)
	{
		m_pNetworkObject->SetSession(NULL);
		m_pNetworkObject = NULL;
	}	
}

bool Session::Send(unsigned char* pMsg, size_t nSize)
{
	return m_pSendBuffer->Write(pMsg, nSize);
}

void Session::OnAccept()
{
	m_pNetworkObject->OnAccept();
}

bool Session::ProcessRecvdPacket(size_t nMaxPacketSize)
{
	return true;
}